<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<style>
    body{
        background: #fff;
    }
</style>
<body>
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<form:form commandName="SysBriefingFilter" cssClass="form-horizontal" role="form" onsubmit="return false;" enctype="multipart/form-data" id="updateForm" action="/common/releaseBriefing/create">
    <div class="form-group">
        <label class="control-label col-sm-2 text-right">周期</label>
        <div class="col-sm-9">
            <select class="form-control" id="cycle" name="period">
                <option value="">点击选择</option>
                <c:forEach items="${weekDocuments}" var="weekDocument">
                    <option category = "${weekDocument.category}" value="${weekDocument.period}">第${weekDocument.period}期</option>
                </c:forEach>
            </select>
            <input type="hidden" name="type">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-offset-1 col-sm-1 text-right">标题</label>
        <div class="col-sm-9">
            <input type="text" class="form-control" name="title">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2 text-right">创建时间</label>
        <div class="col-sm-9">
            <%--creationTime--%>
            <input type="text" class="form-control layui-input"  lay-verify="date" autocomplete="off" name="dateAttr" id="creationTime" readonly placeholder="请选择时间">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-offset-1 col-sm-1 text-right">摘要</label>
        <div class="col-sm-9">
           <textarea class="form-control" rows="3" name="summary"  style="resize: vertical;min-height: 50px"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-offset-1 col-sm-1 text-right">主要内容</label>
        <div class="col-sm-9">
            <div class="summernote"></div>
        </div>
    </div>

    <input type="hidden" value="" name="content">
    <div class="form-group">
        <div class="col-sm-8 col-sm-offset-2 pos-rel">
            <div>
                <div style="display: inline-block">
                    <input type="file" class="fileBorder" id="fileupload">
                </div>
                <div style="display: inline-block">
                    <button class="btn btn-info" onclick="uploadFile(this,'annex','annexName')">
                        <span class="glyphicon glyphicon-open"></span>上传附件
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-2">
            <button class="btn btn-info" id="updateFormButton">确定</button>
            <button class="btn">关闭</button>
        </div>
    </div>
        <%--    简报图片请求格式  --%>
<%--    <img src="/common/releaseBriefing/showEditorImg?fullpath=2019/09/17/15687255910063Es4B.jpg">--%>
</form:form>

<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script type="text/javascript">
    $(function() {
        $('.summernote').summernote({
            height: 200,
            tabsize: 2,
            lang: 'zh-CN',
            //监听上传事件
            callbacks: {
                onImageUpload: function (files, editor, $editable) {
                    sendFile(files);
                }
            }
        });


        //选择创建时间
        $("#creationTime").on("click",function () {
            laydate({
                elem: "#creationTime",
                format: 'YYYY-MM-DD',
                // min: minDate(),
            });
        });
    });
    //上传图片
    function sendFile(files, editor, $editable) {
        var size = files[0].size;
        if((size / 1024 / 1024) > 2) {
            alert("图片大小不能超过2M...");
            return false;
        }
        var formData = new FormData();
        formData.append("file", files[0]);
        $.ajax({
            url: "/common/releaseBriefing/uploadEditorImg",//路径是你控制器中上传图片的方法，
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (data) {
                //debugger;
                console.log(data)
                $('.summernote').summernote('insertImage', data.path);
            }
        });
    }

    $("#updateFormButton").click(function () {
        failure("#updateFormButton",1)
        if(!$("input[name='title']").val()) {
            failure("#updateFormButton",0)
            alert('请输入标题');
            return;
        }
        if ($('.summernote').summernote('isEmpty')) {
            failure("#updateFormButton",0)
            alert('请输入简报内容');
            return;
        }
        if (!$("input[name='dateAttr']").val()) {
            failure("#updateFormButton",0)
            alert('请输入创建时间');
            return;
        }
        if (!$("select[name='period']").val()) {
            failure("#updateFormButton",0)
            alert('请输入周期');
            return;
        }
        var  sHTML = $('.summernote').summernote("code");
        $("input[name='content']").val(sHTML);
        var userData = $("#updateForm").serialize();
        $.ajax({
            url:"/common/releaseBriefing/create",
            data:userData,
            dataType:"json",
            type:"post",
            success:function (res) {
                //console.log(res);
                if (res.code != undefined && res.code =='200'){
                    // alert(data)
                    alert('保存成功')
                    setTimeout(function () {
                        parent.close_current_app();
                    },50)

                } else {
                    //alert(data)
                    alert('保存失败')
                }
            }
        })
        /**
         * 表单颜色的 form 提交
         */
        // $.post($form.attr('action'), $form.serialize(), function(result) {
        //     console.log(result);
        // });
    })

    function rightTipBOX(msg) {
        if(msg == undefined){
            msg = ''
        }
        $.gritter.add({
            title: "提示",
            text: msg
        });
    }

    $("#cycle").change(function () {
       var $category = $(this).find("option:selected").attr("category");
       $(this).siblings("input").val($category)
    })
</script>
</body>
</html>